package com.store.config;

import com.store.Interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 注册登录拦截器
 */
@Configuration
public class LoginInterceptorConfigurer implements WebMvcConfigurer {

    @Resource
    private LoginHandlerInterceptor loginHandlerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptorRegistration = registry.addInterceptor(loginHandlerInterceptor);

        //放行的资源
        List<String> patterns = new ArrayList<>();
        patterns.add("/assets/**");
        patterns.add("/bootstrap3/**");
        patterns.add("/css/**");
        patterns.add("/images/**");
        patterns.add("/js/**");
        patterns.add("/web/**");
        patterns.add("/product/getProdoct");
        patterns.add("/user/login");
        patterns.add("/user/register");
        patterns.add("/");
        patterns.add("/index");
        patterns.add("/go/**");
        patterns.add("/product/getHot");
        patterns.add("/product/getNew");
        patterns.add("/product/getSearch");

        //拦截资源
        interceptorRegistration.addPathPatterns("/**");

        //放行资源
        interceptorRegistration.excludePathPatterns(patterns);
    }
}
